﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;

namespace JohnnySins
{
    public partial class Archives : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
                LoadList();
        }

        protected void rptArchive_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                string rowView = e.Item.DataItem as string;
                HyperLink hl = e.Item.FindControl("hlVideo") as HyperLink;
                hl.Text = rowView;
            }
        }

        protected void upArchive_Load(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(Request["__EVENTARGUMENT"]))
            {
                string date = Request["__EVENTARGUMENT"];
                LoadList();
            }
        }

        protected void LoadList()
        {
            string folder = Server.MapPath("~/Files/Archives");
            List<string> files = new List<string>();
            DirectoryInfo di = new DirectoryInfo(folder);
            foreach (FileInfo fi in di.GetFiles("*.mp4"))
            {
                files.Add(fi.Name);
            }
            files.Sort();
            rptArchive.DataSource = files;
            rptArchive.DataBind();
        }
    }
}